package org.jerrymouse.financeApp;

import java.util.Date;

import org.apache.commons.math.stat.descriptive.SummaryStatistics;
import org.jerrymouse.agentContainer.Agent;

public class FinanceApp extends Agent {
	private String no;

	public void setNo(String no) {
		this.no = no;
	}

	public double companyAvg(Date from, Date to) {
		SummaryStatistics stats = new SummaryStatistics();
		for (double d : getGoogleFinance().getCompanyFinance(no, from, to)) {
			stats.addValue(d);
		}
		return stats.getMean();
	}

	private GoogleFinance getGoogleFinance() {
		return (GoogleFinance) getAgent(GoogleFinance.class);
	}

	public double companyVariance(Date from, Date to) {
		SummaryStatistics stats = new SummaryStatistics();
		for (double d : getGoogleFinance().getCompanyFinance(no, from, to)) {
			stats.addValue(d);
		}
		return stats.getVariance();
	}

	public double tradeAvg(Date from, Date to) {
		SummaryStatistics stats = new SummaryStatistics();
		for (double d : getGoogleFinance().getTradeFinance(no, from, to)) {
			stats.addValue(d);
		}
		return stats.getMean();
	}

	public double tradeVariance(Date from, Date to) {
		SummaryStatistics stats = new SummaryStatistics();
		for (double d : getGoogleFinance().getTradeFinance(no, from, to)) {
			stats.addValue(d);
		}
		return stats.getVariance();
	}

}
